#include <stdio.h>
#include <stdbool.h>

#define MAXSIZE 10

struct LinearList
{
  int data[MAXSIZE];
  int length;
};

void InitList(struct LinearList *ll);
bool ListDelete(struct LinearList *ll, int i, int *e);

int main()
{
  struct LinearList ll;
  InitList(&ll);

  int e = -1;
  if (ListDelete(&ll, 3, &e))
  {
    printf("is Delete third element,number = %d\n", e);
  }
  else
  {
    printf("the index is illegal, delete fail!\n");
  }

  for (int i = 0; i < ll.length; i++)
  {
    printf("data[%d] = %d\n", i, ll.data[i]);
  }

  printf("length = %d\n", ll.length);
  return 0;
}

void InitList(struct LinearList *ll)
{
  for (int i = 0; i < MAXSIZE; i++)
  {
    // init data
    ll->data[i] = 0;
  }

  ll->length = MAXSIZE;
}

bool ListDelete(struct LinearList *ll, int i, int *e)
{
  bool res = true;
  if (i < 1 || i > ll->length)
    res = false;
  *e = ll->data[i - 1]; // 将被删除的元素赋值给e

  for (int j = i; j < ll->length; j++)
  {
    ll->data[j - 1] = ll->data[j]; // 将第 i个后的位置前移一位
  }
  ll->length--;

  return res;
}